package com.sofwin.service.impl;

import com.sofwin.mapper.SysResourceMapper;
import com.sofwin.pojo.SysResource;
import com.sofwin.pojo.SysResourceExample;
import com.sofwin.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @packageName: com.sofwin.service.impl
 * @user: andyliu
 * @date: 2023/1/3 15:55
 * @email 115176513@qq.com
 * @description: TODO
 */
@Service
public class ResourceServiceImpl implements ResourceService {
    @Autowired
    private SysResourceMapper mapper;
    @Override
    public List<SysResource> queryResources(SysResource resource) {
        SysResourceExample example = new SysResourceExample();
        SysResourceExample.Criteria criteria = example.createCriteria();
        if(!StringUtils.isEmpty(resource.getResourceName())){
            criteria.andResourceNameLike("%"+resource.getResourceName()+"%");
        }
        if(resource.getStatus()!=null){
            criteria.andStatusEqualTo(resource.getStatus());
        }
        return mapper.selectByExample(example);
    }

    @Override
    public List<SysResource> queryResourceByRoleId(Integer roleId) {
        return mapper.selectResourceByRoleId(roleId);
    }
}
